package com.lh.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.UUID;

public class LogUtil {

    private Logger LOG;

    public LogUtil(Class<?> clazz) {
        this.LOG = LoggerFactory.getLogger(clazz);
    }

    public <T> Answer<T> error(Answer<T> result, String errorMsg, Exception e) {
        String id = UUID.randomUUID().toString();
        result.setMsg(errorMsg);
        result.setId(id);
        this.LOG.error("[${result.getId()}]-${errorMsg}。", e);
        return result;
    }

    public <T> ResultOne<T> error(ResultOne<T> result, String errorMsg, Exception e) {
        result.setMsg(errorMsg);
        this.LOG.error("[${result.getId()}]-${errorMsg}。", e);
        return result;
    }

    public void error(String errorMsg) {
        this.LOG.error(errorMsg);
    }

    public void info(String errorMsg) {
        this.LOG.info(errorMsg);
    }

    public void info(String format, Object arg1, Object arg2) {
        this.LOG.info(format, arg1, arg2);
    }

    public Logger out() {
        return LOG;
    }
}
